<template>
	<view class="content">
		<custom-tarbar :selected="0"></custom-tarbar>



		<view class="content_item" v-for="(item,index) in activityinfo" :key="index">
			<view class="cu-card article" :class="isCard?'no-card':''">
				<view class="cu-item shadow">
					<view class="title">
						<view class="text-cut">{{item.activityname}}</view>
					</view>
					<view class="content">
						<image :src="item.imagePath[0]" mode="aspectFill"></image>
						<view class="desc">
							<view class=".topic_cont_text text-gray" style="margin: 10rpx;">
								{{item.detailCout}}
							</view>
							<button @click="toDetail(item.activityname)" class="cu-btn round bg-yellow">详情</button>
						</view>
					</view>
				</view>
			</view>
		</view>


		<!-- ======================================== -->
		<down-block></down-block>
	</view>
</template>

<script>
	import customTarbar from '@/wxcomponents/custom-tarbar/custom-tarbar.vue';
	import cuCustom from '../../colorui/components/cu-custom.vue'
	import downBlock from '../../components/down_block.vue'
	export default {
		components: {
			'custom-tarbar': customTarbar,
			cuCustom,
			downBlock
		},
		data() {
			return {
				hasLogin: false,
				isCard: false,
				activityinfo: [],
				baseurl: ""
			}
		},
		methods: {
			toDetail(name) {
				uni.navigateTo({
					url: '../detail/detail?name=' + name
				})
			},
			async getDetail() {
				console.log("?")
				const baseurl = getApp().globalData.BASE_URL
				let inner = this
				uni.request({
					url: baseurl + '/activity/getActivity',
					success(res) {
						inner.activityinfo = res.data;


						// 对图片的url进行遍历修改
						for (let j = 0; j < inner.activityinfo.length; j++) {
							for (let i = 0; i < inner.activityinfo[j].imagePath.length; i++) {
								if (inner.activityinfo[j].imagePath[i].indexOf("http") == -1) {
									// 如果图片url里面没有http字体那边加上baseurl
									inner.activityinfo[j].imagePath[i] = inner.baseurl + inner.activityinfo[j]
										.imagePath[i];
								}
							}
						}
					}
				})
				// 	const res = await this.$myRequest({
				// 		url: '/activity/getActivity'
				// 	})
				// 	console.log(res)
				// 	this.activityinfo = res.data;
				// 	console.log(res)

				// 	// 对图片的url进行遍历修改
				// 	for (let j = 0; j < this.activityinfo.length; j++) {
				// 		for (let i = 0; i < this.activityinfo[j].imagePath.length; i++) {
				// 			if (this.activityinfo[j].imagePath[i].indexOf("http") == -1) {
				// 				// 如果图片url里面没有http字体那边加上baseurl
				// 				this.activityinfo[j].imagePath[i] = this.baseurl + this.activityinfo[j].imagePath[i];
				// 			}
				// 		}
				// 	}


			}

		},
		onShow() {
			console.log("onshow start")
			uni.hideTabBar()

			this.baseurl = getApp().globalData.BASE_URL
			this.hasLogin = uni.getStorageSync("isLogin")
			if (!this.hasLogin) {
				uni.navigateTo({
					url: '../login/login'
				})
			}
		},
		onLoad() {
			// console.log("onload start")
			this.getDetail()
		},
		onInit() {
			// console.log("onInit start")
		},



	};
</script>

<style>
	.content {
		width: 100%;
	}

	.topic_cont_text {

		colof: #999;

		max-height: 130upx;
		overflow: hidden;
		word-break: break-all;
		/* break-all(允许在单词内换行。) */
		text-overflow: ellipsis;
		/* 超出部分省略号 */
		display: -webkit-box;
		/** 对象作为伸缩盒子模型显示 **/
		-webkit-box-orient: vertical;
		/** 设置或检索伸缩盒对象的子元素的排列方式 **/
		-webkit-line-clamp: 3;
		/** 显示的行数 **/

	}
</style>
